package touch;

import android.animation.ObjectAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import org.jaaksi.commondemo.R;
import org.jaaksi.commondemo.util.LogUtil;
import statics.Config;

/**
 * 创建时间：2018年01月05日14:23 <br>
 * 作者：fuchaoyang <br>
 * 描述：
 */

public class TestTouchActivity extends Activity
  implements View.OnClickListener, View.OnTouchListener {
  MyButton btn;

  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_touch);

    btn = (MyButton) findViewById(R.id.btn);
    btn.setOnClickListener(this);
    //btn.setOnTouchListener(this);
    String scheme = Config.SCHEME;
    Log.e("touch", scheme);
  }

  @Override public void onClick(View v) {
    LogUtil.i("touch", "..onClick");
    btn.getLayoutParams().height = 400;
    btn.requestLayout();
  }

  @Override public boolean onTouch(View v, MotionEvent event) {
    LogUtil.i("touch", "..setOnTouchListener");
    return false;
  }

  /**
   * 事件先由Activity的dispatchTouchEvent处理，分发给DecorView，往下分发，如果没有被消费，就会交由 Activity的OnTouch处理
   * super中的逻辑
   * if (ev.getAction() == MotionEvent.ACTION_DOWN) {
   * onUserInteraction();
   * }
   * if (getWindow().superDispatchTouchEvent(ev)) {
   * return true;
   * }
   * return onTouchEvent(ev);
   */
  @Override public boolean dispatchTouchEvent(MotionEvent ev) {
    SoftInputUtil.dispatchTouchEvent(this, ev);
    return super.dispatchTouchEvent(ev);
  }
}
